package org.dtrd.modules.archive.entity.bean.report;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.dtrd.config.system.Constant;
import org.dtrd.modules.archive.entity.po.DtrdEntRdArchiveOverview;

import java.util.Date;
import java.util.Optional;

/**
 * @author qr
 * @date 2022/1/20 14:57
 */
@ApiModel("糖尿病概况")
@Getter
@Setter
public class DiabetesOverviewReport {

    @ApiModelProperty(value = "是否确诊糖尿病")
    private String ifDiabetesText;

    @ApiModelProperty(value = "糖尿病类型：1-1型糖尿病,2-2型糖尿病,3-妊娠糖尿病,4-其他类型糖尿病")
    private String diabetesTypeText;

    @ApiModelProperty(value = "确诊日期")
    @JsonFormat(timezone = "GMT+8", pattern = Constant.TIME_PATTERN_SDF)
    private Date diabetesDiagnoseDate;

    @ApiModelProperty(value = "起病特点Ids，多个用半角逗号隔开")
    private String diabetesOnsetSymptom;

    @ApiModelProperty(value = "早餐前血糖")
    private String sugarBreakfastBefore;

    @ApiModelProperty(value = "早餐后血糖")
    private String sugarBreakfastAfter;

    @ApiModelProperty(value = "午餐前血糖")
    private String sugarLunchBefore;

    @ApiModelProperty(value = "午餐后血糖")
    private String sugarLunchAfter;

    @ApiModelProperty(value = "晚餐前血糖")
    private String sugarSupperBefore;

    @ApiModelProperty(value = "晚餐后血糖")
    private String sugarSupperAfter;

    @ApiModelProperty(value = "睡前血糖")
    private String sugarSleepBefore;

    @ApiModelProperty(value = "夜间血糖")
    private String sugarSleepAfter;

    @ApiModelProperty(value = "糖化血红蛋白")
    private String hba1c;

    @ApiModelProperty(value = "血糖日波动幅度")
    private String sugarWave;

    @ApiModelProperty(value = "早发性心血管疾病家族史")
    private String familyHistoryPrematureAngioText;

    @ApiModelProperty(value = "2型糖尿病家族史")
    private String familyHistoryDiabetes2Text;

    @ApiModelProperty(value = "用药类型")
    private String drugType;



    public DiabetesOverviewReport parseFromPO(DtrdEntRdArchiveOverview po) {
        // 已确诊显示确诊日期
        if (po.getIfDiabetes() != null && po.getIfDiabetes().equals(Constant.DiagnoseStatus.HAD_DIAGNOSED.getType())) {
            diabetesDiagnoseDate = po.getDiabetesDiagnoseDate();
            diabetesTypeText = Optional.ofNullable(po.getDiabetesType()).map(t -> Constant.DiabetesType.valueOf(t).getName()).orElse(null);
        }
        diabetesOnsetSymptom = po.getDiabetesOnsetSymptom();
        if (po.getSugarFasting() != null) {
            sugarBreakfastBefore = po.getSugarFasting() + Constant.Unit.SUGAR_VALUE_UNIT;
        }
        if (po.getSugarBreakfastAfter() != null) {
            sugarBreakfastAfter = po.getSugarBreakfastAfter() + Constant.Unit.SUGAR_VALUE_UNIT;
        }
        if (po.getSugarLunchBefore() != null) {
            sugarLunchBefore = po.getSugarLunchBefore() + Constant.Unit.SUGAR_VALUE_UNIT;
        }
        if (po.getSugarLunchAfter() != null) {
            sugarLunchAfter = po.getSugarLunchAfter() + Constant.Unit.SUGAR_VALUE_UNIT;
        }
        if (po.getSugarSupperBefore() != null) {
            sugarSupperBefore = po.getSugarSupperBefore() + Constant.Unit.SUGAR_VALUE_UNIT;
        }
        if (po.getSugarSupperAfter() != null) {
            sugarSupperAfter = po.getSugarSupperAfter() + Constant.Unit.SUGAR_VALUE_UNIT;
        }
        if (po.getSugarSleepBefore() != null) {
            sugarSleepBefore = po.getSugarSleepBefore() + Constant.Unit.SUGAR_VALUE_UNIT;
        }
        if (po.getSugarSleepAfter() != null) {
            sugarSleepAfter = po.getSugarSleepAfter() + Constant.Unit.SUGAR_VALUE_UNIT;
        }
        if (po.getHba1c() != null) {
            hba1c = po.getHba1c() + "%";
        }
        if (po.getSugarWave() != null) {
            sugarWave = Constant.SugarWave.valueOf(po.getSugarWave()).getName();
        }
        if (po.getDrugType() != null) {
            drugType = Constant.DrugType.valueOf(po.getDrugType()).getName();
        }
        familyHistoryPrematureAngioText = Optional.ofNullable(po.getFamilyHistoryPrematureAngio()).map(t -> Constant.YesOrNo.valueOf(t).getName()).orElse(null);
        familyHistoryDiabetes2Text = Optional.ofNullable(po.getFamilyHistoryDiabetes2()).map(t -> Constant.YesOrNo.valueOf(t).getName()).orElse(null);
        return this;
    }
}
